var NetSocket = require('NetSocket');
var Observer = require('Observer');
var GameData = require('GameData');

cc.Class({
    extends: Observer,

    properties: {
        _playNum: 4,// 局数 4: 4局(2房卡)  8: 8局(4房卡)  16: 16局(8房卡)
        _pao: 4,
        _hu: false,// false自摸胡, true点炮胡
        _hun: false,
        _gang_dai_pao: false,
        _dai_zi_pai: false,
        _7dui: false,
        _zhuangjia: false,
        _gang_kai: false,
    },

    onLoad: function () {
        this._initMsg();

    },
    _onMsg(msg, data){
        if (msg == MJNetMsg.recv.CreateRoom.msg) {
            if (data.result) {// 创建房间成功
                GameData.setRoomCfg(this._playNum, this._pao, this._hu, this._hun,
                    this._gang_dai_pao, this._dai_zi_pai, this._7dui,
                    this._zhuangjia, this._gang_kai);
                GameData.setRoomID(data.roomId);
            } else {

            }
            this.node.destroy();
        }
    },
    _getMsgList(){
        return [MJNetMsg.recv.CreateRoom.msg];
    },

    onClickClose(){
        this.node.destroy();
    },
    // 创建房间
    onCreateRoom(){
        var data = {
            profile: "bj",
            options: [
                {key: "chapterMax", value: this._playNum.toString()},
                {key: "XUAN_PAO_COUNT", value: this._pao.toString()},
                {key: "IS_FANG_PAO", value: this._hu},
                {key: "IS_HUIER", value: this._hun},
                {key: "IS_GANG_DAI_PAO", value: this._gang_dai_pao},
                {key: "IS_DAI_ZI_PAI", value: this._dai_zi_pai},
                {key: "IS_QI_DUI_FAN_BEI", value: this._7dui},
                {key: "IS_ZHUANG_JIA_DI", value: this._zhuangjia},
                {key: "IS_GANG_KAI_FAN_BEI", value: this._gang_kai},
            ],
        };
        NetSocket.send(MJNetMsg.send.CreateRoom, data);
    },
    onClickNum4(event){
        this._playNum = 4;
    },
    onClickNum8(){
        this._playNum = 8;
    },
    onClickNum16(){
        this._playNum = 16;
    },
    // 自摸胡
    onClickHuZiMo(){
        this._hu = false;
    },
    // 点炮胡
    onClickHuDianPao(){
        this._hu = true;
    },
    // 四局选跑
    onClickPao4(){
        this._pao = 4;
    },
    // 每局选跑
    onClickPao1(){
        this._pao = 1;
    },
    // 带混
    onClickHun(){
        this._hun = true;
    },
    // 杠带跑
    onClickGangDaiPao(){
        this._gang_dai_pao = true;
    },
    // 带字牌
    onClickDaiZiPai(){
        this._dai_zi_pai = true;
    },
    // 七对翻倍
    onClickDui7(){
        this._7dui = true;
    },
    // 庄家翻倍
    OnClickZhuangJia(){
        this._zhuangjia = true;
    },
    // 杠开翻倍
    OnClickGangKai(){
        this._gang_kai = true;
    },

});
